package com.lxp.project.system.service.impl;

import com.lxp.project.system.domain.SysUserPost;
import com.lxp.project.system.mapper.SysUserPostMapper;
import com.lxp.project.system.service.ISysUserPostService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
public class SysUserPostServiceImpl extends ServiceImpl<SysUserPostMapper, SysUserPost> implements ISysUserPostService {
    @Override
    public int deleteUserPostByUserId(Long userId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq(SysUserPost::getUserId, userId);
        return this.mapper.deleteByQuery(wrapper);
    }

    @Override
    public long countUserPostById(Long postId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq(SysUserPost::getPostId, postId);
        return this.count(wrapper);
    }

    @Override
    public int deleteUserPost(Long[] ids) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in(SysUserPost::getUserId, Arrays.asList(ids));
        return this.mapper.deleteByQuery(wrapper);
    }

    @Override
    @Transactional
    public int batchUserPost(List<SysUserPost> userPostList) {
        return this.saveBatch(userPostList) ? userPostList.size() : 0;

    }
}
